package com.tanhua.dubbo.api;

import com.baomidou.mybatisplus.core.conditions.query.QueryWrapper;
import com.baomidou.mybatisplus.core.metadata.IPage;
import com.baomidou.mybatisplus.extension.plugins.pagination.Page;
import com.tanhua.domain.db.Announcement;
import com.tanhua.domain.vo.PageResult;

import com.tanhua.dubbo.mapper.AnnouncementMapper;
import org.apache.dubbo.config.annotation.Service;
import org.springframework.beans.factory.annotation.Autowired;
@Service
public class AnnouncementApiImpl implements AnnouncementApi {
    @Autowired
    private AnnouncementMapper announcementMapper;
    @Override
    public PageResult<Announcement> findAll(int page, int pagesize) {
        Page<Announcement> ipage = new Page<>(page,pagesize);
        QueryWrapper<Announcement> queryWrapper = new QueryWrapper<>();
        queryWrapper.orderByDesc("created");
        IPage<Announcement> iPage = announcementMapper.selectPage(ipage, queryWrapper);
        return new PageResult<>((int)iPage.getTotal(),pagesize,(int)iPage.getPages(),page,iPage.getRecords());
    }
}
